import QtQuick 2.15
import QtQuick.Controls 2.15
import Backend 1.0

GridView {
    property int mtype: appModel.type

    id: gridView
    cellHeight: 120
    cellWidth: 120
    focus: true
    boundsBehavior: Flickable.StopAtBounds

    delegate: ApplicationDelegate {
        id: appDelegate
    }

    model: AppDataModel {
        id: appModel
    }

    // 拖拽释放区域
    Rectangle {
        id: dropDesc
        width: gridView.width / 2 + 50
        height: gridView.height / 2 + 50
        anchors.verticalCenter: gridView.verticalCenter
        anchors.horizontalCenter: parent.horizontalCenter
        color: "#a9a9a9"
        border.width: 5
        border.color: "gray"
        radius: 25
        visible: false
        Label {
            id: dropDescText
            text: "请拖动图标到此区域"
            font.bold: true
            font.pixelSize: 20
            font.family: "Microsoft YaHei"
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.verticalCenter: parent.verticalCenter
        }
    }
    DropArea {
        id: dropArea
        anchors.fill: gridView
        // 拖入区域标记为捕获
        onEntered: {
            if (mtype !== drag.source.dType) {
                drag.source.caught = true
                dropDesc.visible = true
                drag.source.add(appModel)
            }
        }
        // 离开区域取消标记
        onExited: {
            if (mtype !== drag.source.dType) {
                drag.source.caught = false
                dropDesc.visible = false
            }
        }
    }

    ScrollBar.vertical: ScrollBar {}
}
